home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 66
/
Vol 66.iso
/
games
/
bob_espo.swf
/
scripts
/
__Packages
/
Sounds.as
< prev
next >
Wrap
Text File
|
2013-04-24
|
8KB
|
282 lines
class Sounds
{
static var nFADE_SPEED = 5;
function Sounds(_mcTimeline)
{
this.mcTimeLine = _mcTimeline;
this.init();
this.mcRef = _mcTimeline.mcSounds;
this.mcRef.onEnterFrame = Delegate.create(this,this.enterFrame);
}
function isSoundsMuted()
{
return this.bMuteSound;
}
function isMusicMuted()
{
return this.bMuteMusic;
}
function playSound(_sName, _nVolume, _nLoop)
{
if(!this.exist(_sName))
{
this.oSounds[_sName] = new Object();
this.oSounds[_sName].sName = _sName;
this.oSounds[_sName].nVolume = 0;
this.oSounds[_sName].nPausePosition = 0;
this.oSounds[_sName].mcRef = this.mcTimeLine.createEmptyMovieClip(_sName,this.nDepth);
this.oSounds[_sName].sSound = new Sound(_sName);
this.oSounds[_sName].sSound.attachSound(_sName);
if(_sName == Controller.PACKAGING_INTRO_MUSIC_NAME)
{
this.oSounds[_sName].sSound.onSoundComplete = Delegate.create(Controller.getRef(),Controller.getRef().introComplete);
}
this.nDepth = this.nDepth + 1;
}
if(this.exist(_sName))
{
this.setVolumeSound(_sName,_nVolume);
this.oSounds[_sName].sSound.start(0,_nLoop);
if(this.isMusic(_sName))
{
if(this.bMuteMusic)
{
this.oSounds[_sName].sSound.setVolume(0);
}
}
else if(this.bMuteSound)
{
this.oSounds[_sName].sSound.setVolume(0);
}
}
}
function playRandomSound(_nMaxSounds, _sSoundName, _nVolume)
{
var _loc5_ = Math.round(Math.random() * (_nMaxSounds - 1));
_loc5_ = _loc5_ + 1;
this.playSound(_sSoundName + "(" + _loc5_ + ")",_nVolume,1);
}
function stopSound(_sName)
{
if(this.exist(_sName))
{
this.setVolumeSound(_sName,0);
this.oSounds[_sName].sSound.stop();
}
}
function pauseSound(_sName)
{
if(this.exist(_sName))
{
if(!this.isMusic(_sName))
{
if(this.oSounds[_sName].nPausePosition == -1)
{
this.oSounds[_sName].nPausePosition = 0;
}
else
{
this.oSounds[_sName].nPausePosition = this.oSounds[_sName].sSound.position;
}
this.oSounds[_sName].sSound.stop();
}
}
}
function resumeSound(_sName)
{
if(this.exist(_sName))
{
if(!this.isMusic(_sName))
{
if(this.oSounds[_sName].nPausePosition != 0 && this.oSounds[_sName].nPausePosition != undefined)
{
this.oSounds[_sName].sSound.start(this.oSounds[_sName].nPausePosition / 1000,0);
}
}
}
}
function pauseAllSounds()
{
for(var i in this.oSounds)
{
this.pauseSound(this.oSounds[i].sName);
}
}
function resumeAllSounds()
{
for(var i in this.oSounds)
{
this.resumeSound(this.oSounds[i].sName);
}
}
function startFadeIn(_sName, _nVolume, _nLoop)
{
if(!this.bMuteSound && !this.isMusic(_sName) || !this.bMuteMusic && this.isMusic(_sName))
{
this.playSound(_sName,0,_nLoop);
var _loc5_ = [_sName,_nVolume,"In",0];
this.aTabSonFade.push(_loc5_);
}
else
{
this.playSound(_sName,_nVolume,_nLoop);
}
}
function startFadeOut(_sName)
{
if(this.exist(_sName))
{
this.aTabSonFade = [];
if(this.oSounds[_sName].sSound.getVolume() != 0)
{
var _loc3_ = [_sName,0,"Out",this.oSounds[_sName].sSound.getVolume()];
this.aTabSonFade.push(_loc3_);
}
else
{
this.stopSound(_sName);
}
}
}
function setVolumeSound(_sName, _nVolume)
{
if(this.exist(_sName))
{
this.oSounds[_sName].nVolume = _nVolume;
if(this.bMuteSound && !this.isMusic(_sName) || this.bMuteMusic && this.isMusic(_sName))
{
this.oSounds[_sName].sSound.setVolume(0);
}
else
{
this.oSounds[_sName].sSound.setVolume(_nVolume);
}
}
}
function DoMuteSounds()
{
this.bMuteSound = true;
for(var i in this.oSounds)
{
if(!this.isMusic(this.oSounds[i].sName))
{
this.oSounds[this.oSounds[i].sName].sSound.setVolume(0);
}
}
}
function UndoMuteSounds()
{
this.bMuteSound = false;
for(var i in this.oSounds)
{
if(!this.isMusic(this.oSounds[i].sName))
{
this.setVolumeSound(this.oSounds[i].sName,this.oSounds[i].nVolume);
}
}
}
function DoMuteMusic()
{
this.bMuteMusic = true;
for(var i in this.oSounds)
{
if(this.isMusic(this.oSounds[i].sName))
{
this.oSounds[this.oSounds[i].sName].sSound.setVolume(0);
}
}
}
function UndoMuteMusic()
{
this.bMuteMusic = false;
for(var i in this.oSounds)
{
if(this.isMusic(this.oSounds[i].sName))
{
this.setVolumeSound(this.oSounds[i].sName,this.oSounds[i].nVolume);
}
}
}
function enterFrame()
{
for(var i in this.aTabSonFade)
{
var _loc2_ = this.aTabSonFade[i][0];
var _loc3_ = this.aTabSonFade[i][1];
var _loc4_ = this.aTabSonFade[i][2];
var _loc5_ = this.aTabSonFade[i][3];
if(_loc4_ == "In")
{
_loc5_ += this.nFadingSpeed;
if(_loc5_ >= _loc3_)
{
_loc5_ = _loc3_;
this.deleteFading(_loc2_);
if(this.aTabSonFade.length == 0)
{
delete this.oSounds[_loc2_].mcRef.onEnterFrame;
}
}
}
else
{
_loc5_ -= this.nFadingSpeed;
if(_loc5_ <= 0)
{
this.stopSound(_loc2_);
_loc5_ = 0;
this.deleteFading(_loc2_);
if(this.aTabSonFade.length == 0)
{
delete this.oSounds[_loc2_].mcRef.onEnterFrame;
}
}
}
if(_loc5_ != 0)
{
this.aTabSonFade[i][3] = _loc5_;
}
this.setVolumeSound(_loc2_,_loc5_);
}
}
function deleteFading(_sName)
{
var _loc3_ = 0;
while(_loc3_ <= this.aTabSonFade.length)
{
if(this.aTabSonFade[_loc3_][0] == _sName)
{
this.aTabSonFade.splice(_loc3_,1);
}
_loc3_ = _loc3_ + 1;
}
}
function init()
{
this.oSounds = {};
this.aTabSonFade = [];
this.bMuteMusic = false;
this.bMuteSound = false;
this.nDepth = 0;
this.nFadingSpeed = Sounds.nFADE_SPEED;
}
function exist(_sName)
{
var _loc3_ = false;
if(this.oSounds[_sName])
{
_loc3_ = true;
}
return _loc3_;
}
function isMusic(_sName)
{
var _loc3_ = false;
if(_sName == Controller.GAME_MUSIC_NAME || (_sName == Controller.PACKAGING_INTRO_MUSIC_NAME || _sName == Controller.PACKAGING_MUSIC_NAME))
{
_loc3_ = true;
}
return _loc3_;
}
}